package com.stylefeng.guns.modular.system.warpper;

import com.stylefeng.guns.common.constant.factory.ConstantFactory;
import com.stylefeng.guns.common.warpper.BaseControllerWarpper;
import com.stylefeng.guns.core.util.ToolUtil;
import com.stylefeng.guns.modular.util.StringUtil;
import com.stylefeng.guns.common.persistence.model.Dict;

import java.util.List;
import java.util.Map;

import org.springframework.util.LinkedCaseInsensitiveMap;

/**
 * 字典列表的包装
 *
 * @author fengshuonan
 * @date 2017年4月25日 18:10:31
 */
public class DictWarpper extends BaseControllerWarpper {

	public DictWarpper(Object list) {
		super(list);
	}

	@Override
	public void warpTheMap(Map<String, Object> map) {
		Map<String, Object> tempMap = new LinkedCaseInsensitiveMap<Object>();
		tempMap.putAll(map);
		map.putAll(tempMap);
		StringBuffer detail = new StringBuffer();
		Integer id = Integer.parseInt(StringUtil.nullToDefault(map.get("ID"), "0"));
		List<Dict> dicts = ConstantFactory.me().findInDict(id);
		if (dicts != null) {
			for (Dict dict : dicts) {
				detail.append(dict.getNum() + ":" + dict.getName() + ",");
			}
			map.put("DETAIL", ToolUtil.removeSuffix(detail.toString(), ","));
		}
	}

}
